package xuliehualiu;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Collections;

public class demo2 {
    public static void main(String[] args) throws IOException {
        Student s1=new Student("张三",18,"北京");
        Student s2=new Student("李四",28,"上海");
        Student s3=new Student("王五",19,"武汉");
        ArrayList<Student> list=new ArrayList<>();
        Collections.addAll(list,s1,s2,s3);
        /*
          构造方法：
                public ObjectOutputStream(OutputStream out)         把基本流变成高级流
           成员方法：
                public final void writeObject(Object obj)           把对象序列化（写出）到文件中去

         */

         //1.创建序列性
        ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("h.txt"));
        //2.写入本地文件
        oos.writeObject(list);
        oos.close();

    }
}
